package com.ruoyi.cmdb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cmdb.domain.TbIp;
import com.ruoyi.cmdb.service.ITbIpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * ip列表Controller
 * 
 * @author ruoyi
 * @date 2023-01-25
 */
@RestController
@RequestMapping("/cmdb/ip")
public class TbIpController extends BaseController
{
    @Autowired
    private ITbIpService tbIpService;

    /**
     * 查询ip列表列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbIp tbIp)
    {
        startPage();
        List<TbIp> list = tbIpService.selectTbIpList(tbIp);
        return getDataTable(list);
    }

    /**
     * 导出ip列表列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:export')")
    @Log(title = "ip列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbIp tbIp)
    {
        List<TbIp> list = tbIpService.selectTbIpList(tbIp);
        ExcelUtil<TbIp> util = new ExcelUtil<TbIp>(TbIp.class);
        util.exportExcel(response, list, "ip列表数据");
    }

    /**
     * 获取ip列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbIpService.selectTbIpById(id));
    }

    /**
     * 新增ip列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:add')")
    @Log(title = "ip列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbIp tbIp)
    {
        return toAjax(tbIpService.insertTbIp(tbIp));
    }

    /**
     * 修改ip列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:edit')")
    @Log(title = "ip列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbIp tbIp)
    {
        return toAjax(tbIpService.updateTbIp(tbIp));
    }

    /**
     * 删除ip列表
     */
    @PreAuthorize("@ss.hasPermi('cmdb:ip:remove')")
    @Log(title = "ip列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbIpService.deleteTbIpByIds(ids));
    }
}
